home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / doom / tw212_sv.zip / TWQWSRC / IDENT.QC < prev    next >
Text File  |  1997-05-07  |  2KB  |  71 lines

  1. // Identify the player you are pointed towards
  2. // By Suck (Nat Friedman)
  3. // This code falls under the GNU public license, and cannot be 
  4. // redistributed without my name attached.
  5.  
  6. // hacked by Zoid for CTF4
  7.  
  8. // This is called with the player who wants to know whose in front
  9. // of him as "self."  I call it with an impulse in weapons.qc 
  10. entity(float disp) identify_player =
  11. {
  12.     // e is a temp entity; guy is our current best guess
  13.     // as to at whom the player is pointing
  14.     local entity e, guy;
  15.  
  16.     // The best "closeness" heuristic so far.
  17.     local float closeness = -1;
  18.  
  19.     // Temp vars.
  20.     local vector diff, point;
  21.     local float currclose;
  22.     local string s1, s2, s3;
  23.  
  24.     // Walk the list of players...
  25.     e=find(world, classname, "player");
  26.     while (e!=world)
  27.     {
  28.         // Get a vector pointing from the viewer to the current
  29.         // player under consideration
  30.         diff=e.origin - self.origin;
  31.  
  32.         // Normalize it since we only care where he's pointing,
  33.         // not how far away the guy is.
  34.         diff=normalize(diff);
  35.  
  36.         // Normalize self.angles so we can do a length-independent
  37.         // consideration
  38.         point=normalize(self.angles);
  39.  
  40.         // Find the different between the current player's angle
  41.         // and the viewer's vision angle
  42.         diff=diff - point;
  43.  
  44.         // The length is going to be our definition of closeness
  45.         currclose=vlen(diff);
  46.         traceline(self.origin, e.origin, FALSE, self);
  47.         if (trace_ent == e) {
  48.             if (closeness == -1) {
  49.                 closeness = currclose;
  50.                 guy = e;
  51.             } else if (currclose < closeness) {
  52.                 closeness = currclose;
  53.                 guy = e;
  54.             }
  55.         }
  56.         e=find(e, classname, "player");
  57.     }
  58.  
  59.     // Now we display.
  60.     if (disp==0)
  61.         return guy;
  62.     if (guy == world)
  63.     {
  64.         TeamPlayerUpdate(self, "You're not looking at anyone!");
  65.         return world;
  66.     }
  67.     TeamPlayerUpdate2(self, "You are looking at ", guy.netname);
  68.     return guy;
  69. };     
  70.  
  71.